From 9c5d4da2c43e48fdbf685277138e983cb1e042dc Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 23 Aug 2016 02:59:31 +0300 Subject: [PATCH] Regression test for lockfile format --- tests/cargotest/support/mod.rs | 2 +- tests/lockfile-compat.rs | 51 ++++++++++++++++++++++++++++++++-- 2 files changed, 49 insertions(+), 4 deletions(-) diff --git a/tests/cargotest/support/mod.rs b/tests/cargotest/support/mod.rs index 13397811f..8ade994c9 100644 --- a/tests/cargotest/support/mod.rs +++ b/tests/cargotest/support/mod.rs @@ -412,7 +412,7 @@ impl Execs { } } -fn lines_match(expected: &str, mut actual: &str) -> bool { +pub fn lines_match(expected: &str, mut actual: &str) -> bool { for (i, part) in expected.split("[..]").enumerate() { match actual.find(part) { Some(j) => { diff --git a/tests/lockfile-compat.rs b/tests/lockfile-compat.rs index 4ebba15ea..5fa34452b 100644 --- a/tests/lockfile-compat.rs +++ b/tests/lockfile-compat.rs @@ -7,7 +7,7 @@ use std::io::prelude::*; use cargotest::support::git; use cargotest::support::registry::Package; -use cargotest::support::{execs, project}; +use cargotest::support::{execs, project, lines_match}; use hamcrest::assert_that; #[test] @@ -277,6 +277,52 @@ unable to verify that `foo v0.1.0 ([..])` is the same as when the lockfile was g ")); } +#[test] +fn current_lockfile_format() { + Package::new("foo", "0.1.0").publish(); + + let p = project("bar") + .file("Cargo.toml", r#" + [package] + name = "bar" + version = "0.0.1" + authors = [] + + [dependencies] + foo = "0.1.0" + "#) + .file("src/lib.rs", ""); + p.build(); + + assert_that(p.cargo("build"), execs().with_status(0)); + + let mut actual = String::new(); + File::open(p.root().join("Cargo.lock")).unwrap() + .read_to_string(&mut actual).unwrap(); + + let expected = "\ +[root] +name = \"bar\" +version = \"0.0.1\" +dependencies = [ + \"foo 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)\", +] + +[[package]] +name = \"foo\" +version = \"0.1.0\" +source = \"registry+https://github.com/rust-lang/crates.io-index\" + +[metadata] +\"checksum foo 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)\" = \"[..]\""; + + for (l, r) in expected.lines().zip(actual.lines()) { + assert!(lines_match(l, r), "Lines differ:\n{}\n\n{}", l, r); + } + + assert_eq!(actual.lines().count(), expected.lines().count()); +} + #[test] fn lockfile_without_root() { Package::new("foo", "0.1.0").publish(); @@ -309,8 +355,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" File::create(p.root().join("Cargo.lock")).unwrap() .write_all(lockfile.as_bytes()).unwrap(); - assert_that(p.cargo("build"), - execs().with_status(0)); + assert_that(p.cargo("build"), execs().with_status(0)); let mut lock = String::new(); File::open(p.root().join("Cargo.lock")).unwrap() -- 2.30.2